package org.example.myleet.p1184;

public class Solution {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int clockwise = 0, counterClockwise = 0, i = start - 1;
        do {
            ++i;
            if (i >= distance.length) {
                i = 0;
            }
            if (i == destination) {
                break;
            }
            clockwise += distance[i];
        } while (true);
        i = start;
        if (i != destination) {
            do {
                --i;
                if (i < 0) {
                    i += distance.length;
                }
                counterClockwise += distance[i];
            } while (i != destination);
        }
        return Math.min(clockwise, counterClockwise);
    }
}
